package com.zankong.tool.zkappforas.div_item;

import android.support.annotation.NonNull;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.view.ViewGroup;

import com.zankong.tool.zkapp.document.ZKDocument;
import com.zankong.tool.zkapp.item.HolderInit;
import com.zankong.tool.zkapp.item.ZKAdapter;
import com.zankong.tool.zkapp.util.ZKAppAdapter;
import com.zankong.tool.zkappforas.R;

import org.dom4j.Attribute;
import org.dom4j.Element;

import java.util.HashMap;

/**
 * Created by YF on 2018/9/17.
 */

@ZKAppAdapter("sos_list")
public class SOS_list extends ZKAdapter {
    private final int STATE_ING = 0,
                        STATE_ED = 1;
    private HashMap<String ,String> mClickMap;
    private HashMap<String,Integer> mStates = new HashMap<String,Integer>(){{
        put("ing",STATE_ING);
        put("ed",STATE_ED);
    }};

    public SOS_list(ZKDocument zKDocument, Element element) {
        super(zKDocument, element);
        mClickMap = new HashMap<>();
        for (Attribute attribute : element.element("sos_list").attributes()) {
            mClickMap.put(attribute.getName(),attribute.getValue());
        }
    }

    @Override
    protected RecyclerView.ViewHolder onCreate(@NonNull ViewGroup viewGroup, int i) {
        RecyclerView.ViewHolder holder = null;
        switch (i){
            case STATE_ING:
                holder = new SOSingHolder(mLayoutInflater.inflate(R.layout.item_sos_ing,viewGroup,false));
                break;
            case STATE_ED:
                holder = new SOSedHolder(mLayoutInflater.inflate(R.layout.item_sos_ed,viewGroup,false));
                break;
        }
        return holder;
    }

    @Override
    protected int getVIewType(int position) {
        return mStates.get(mList.get(position).getString("status"));
    }

    @Override
    protected void onBind(@NonNull RecyclerView.ViewHolder viewHolder, int position) {
        if (viewHolder instanceof HolderInit) {
            ((HolderInit) viewHolder).init(position);
        }
    }

    private class SOSingHolder extends RecyclerView.ViewHolder implements HolderInit {
        public SOSingHolder(@NonNull View itemView) {
            super(itemView);
        }

        @Override
        public void init(int position) {

        }
    }
    private class SOSedHolder extends RecyclerView.ViewHolder implements HolderInit {

        public SOSedHolder(@NonNull View itemView) {
            super(itemView);
        }

        @Override
        public void init(int position) {

        }
    }
}
